var app = getApp();
Page({
    data:{
        siteroot : app.siteInfo.siteroot.replace('app/index.php', ''),uniacid: app.siteInfo.uniacid,
        curPage : "/zofui_sales/jifen/index",
        page : {
            isend : false,
            doing : false,
            doo : 'jifen',
            pdata : {
                op : 'indexlist',
                page : 1,
                sortid : 0,
            },
            waitf : 0,
            nodataf : 0,
        },
        datalist : [],
        Menu: [{
            url: "/zofui_sales/pages/index/index",
            iconPath: "/images/menu01.png",
            selectedIconPath: "/images/menu01.png",
            title: "首页",
            type: "tabbar"
        }, {
            url: "/zofui_sales/jifen/index",
            iconPath: "/images/jf_a.png",
            selectedIconPath: "/images/jf_a1.png",
            title: "兑换"
        }, {
            url: "/zofui_sales/jifen/order",
            iconPath: "/images/menu04.png",
            selectedIconPath: "/images/menu04-on.png",
            title: "订单"
        }],
        isIPX : app.globalData.isIPX,
        buttons : [{
            type: "default",
            text: "取消",
            fn: "cancel"
        }, {
            type: "primary",
            text: "确定",
            fn: "confirm"
        }],
        prompt : [{placeholder:'输入密码',response:'code'}],
		
    },
    onLoad:function(options){
        var self = this;
        var uid = options.uid ? options.uid : '';
        self.setData({
            options : options,
            'page.pdata.page' : 1,
        });
        app.com.auth(function(user){
            app.com.getPage(self,self.data.page,20,function(res){
                var data = res.data.data;
                self.setData({
                   datalist : data.list,
                   Pagetheme : res.data.data.params.style,
				   params : res.data.data.params,
                   sharedata : res.data.data.sharedata,
                   userinfo : res.data.data.userinfo,
                   sort : data.sort,
                },function(){
                    self.setData({
                        inited : true,
                    });
                });

                var maincolor = app.com.mainColor(data.params.style);
                wx.setNavigationBarColor({
                    frontColor: '#ffffff',
                    backgroundColor: maincolor,
                });
                

            },false,function(res){
                app.com.alert(res.data.message);
            });
        });
        wx.setNavigationBarTitle({
          title:  '兑换中心',
        });
       
    },
    onShareAppMessage : function(){
        var self = this;
        return {
            title: self.data.article.title,
            path: '',
            imageUrl : self.data.article.img,
        }
    },
    onPullDownRefresh: function () {
        if( this.data.isdown ) return false;

        this.data.isdown = true;
        this.onLoad( this.data.options );
        this.data.isdown = false;

        // 关闭下拉刷新
        wx.stopPullDownRefresh();
    },
    onReachBottom : function(){
        var self = this;
        app.com.getPage(self,self.data.page,20,function(res){
            self.setData({
                datalist : self.data.datalist.concat(res.data.data.list)
            });
        });
    },
    onPageScroll : function(e){
        if( e.scrollTop >= 90 ){
            if( this.data.istop ) return false;
            this.setData({istop:true});
        }else{
            if( !this.data.istop ) return false;
            this.setData({istop:false});
        }
    },
    tabChange(e){
        var self = this;
        if( self.data.ising ) return false;
        self.data.ising = true;

        self.setData({
            'page.pdata.sortid' : e.detail.name,
            'page.pdata.page' : 1,
            'page.isend' : false,
            'page.waitf' : 0,
            'page.nodataf' : 0
        });

        app.com.getPage(self,self.data.page,20,function(res){
            self.setData({
                datalist : res.data.data.list,
            });
        });

        self.data.ising = false;
    },
    onSearch(e){
        var self = this;
        self.setData({
            datalist : [],
            'page.pdata.search' : e.detail,
            'page.pdata.page' : 1,
            'page.isend' : false,
            'page.waitf' : 0,
            'page.nodataf' : 0
        });

        app.com.getPage(self,self.data.page,20,function(res){
            self.setData({
                datalist : res.data.data.list,
            });
        });
    },
    onclear(){
        var e = {
            detail : '',
        }
        this.onSearch(e);
    },
    blursearch(){
        this.setData({
            searching : false,
        })
    },
    searchinput(e){
        var self = this;
        self.setData({
            search : e.detail.value,
        });
    },
    bindCode(){
        this.setData({
            cvisible : true
        })
    },
    cancel(){
        this.setData({
            cvisible : false
        })
    },
    code(e){
        this.setData({
            code : e.detail.value
        })
    },
    confirm(){
        var self = this;
        app.com.http('jifen','POST',{op:'passbycode',code:self.data.code},0,true,'','',function(res){
            if (!res.data.errno) {
                app.com.toast(res.data.message,'success',function(){
                    self.setData({
                        'userinfo.jifen' : res.data.data.jifen,
                        cvisible : false,
                    });
                });
            }else{
                app.com.alert(res.data.message);
            }
        });
    },
    location : function( e ){
        app.com.location( e );
    },
    otherapp : function( e ){
        app.com.otherapp( e );
    },
    navigateto : function( e ){
        app.com.navigateto( e );
    },
    redirectto : function( e ){
        app.com.redirectto( e );
    },    
    callphone : function(e){
        app.com.callphone( e );
    },
    toweburl : function(e){
        app.com.toweburl( e );
    },
    showimages : function( e ){
        app.com.showimages( e );
    },
    footNavigate(e){
        var url = e.currentTarget.dataset.url;
        wx.switchTab({
          url: url
        })
    },

})